package builder;

public class MarkdownBuilder implements DocumentBuilder {
    private Document document;

    public MarkdownBuilder() {
        this.document = new Document();
        this.document.setType("markdown");
    }

    @Override
    public void setTitle(String title) {
        document.setTitle(title);
    }

    @Override
    public void setContent(String content) {
        document.setContent(content);
    }

    @Override
    public void addImage(String url, String alt) {
        document.addImage(new Document.Image(url, alt));
    }

    @Override
    public void addAttachment(String name, String path) {
        document.addAttachment(new Document.Attachment(name, path));
    }

    @Override
    public Document getDocument() throws IllegalArgumentException {
        if (!document.isValid()) {
            throw new IllegalArgumentException("Markdown文档必须包含标题和正文");
        }
        return document;
    }
}